package demo;

import sun.reflect.generics.tree.Tree;

import java.util.*;
import java.util.stream.Collectors;

//Day8
public class Day18007 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Student02> listStudent = new ArrayList<>();
        List<String> listString = new ArrayList<>();
        TreeMap<Student02, String> map = new TreeMap<>();
//        输入名字和年龄
        for (int i = 0; i < 3; i++) {
            System.out.println("输入第" + (i + 1) + "个人名字和年龄");
            listStudent.add(new Student02(scanner.next(), scanner.nextInt()));
        }
//        输入居住地址
        for (int i = 0; i < 3; i++) {
            System.out.println("输入第" + (i + 1) + "个人居住地址");
            listString.add(scanner.next());
        }
//        将信息放入到map
        for (int i = 0; i < 3; i++) {
            map.put(listStudent.get(i), listString.get(i));
        }
        System.out.println(map);
//        筛选出所有姓张的
        List<Student02> list = map.keySet().stream().filter(student02 -> (student02.getName().indexOf("张") != -1)).collect(Collectors.toList());
        for (Student02 s:
             list) {
            System.out.println(s+"---"+map.get(s));
        }
    }

}

//学生类
class Student02 implements Comparable<Student02> {
    private String name;
    private Integer age;

    public Student02() {
    }

    public Student02(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student02{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Student02 student02) {
        int result = student02.getAge() - this.getAge();
        if (result == 0)
            result = this.getName().compareTo(student02.getName());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (obj == this)
            return true;
        if (obj instanceof Student02) {
            if (this.getName().equals(((Student02) obj).getName()) && this.getAge() == ((Student02) obj).getAge())
                return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
